using System;
using System.Collections.Generic;
using System.Text;
using Terminal.Advanced_AEUC_settings_controls.Settings_Interfaces;

namespace Terminal.Advanced_AEUC_settings_controls.Settings_AUX
{
    /// <summary>
    /// Represents a generic enumeration setting item
    /// </summary>
    public class GenAEUCEnumerationItem : IAEUCSerialization
    {
        /// <summary>
        /// The string display name of the item
        /// </summary>
        public string AEUC_displayname;
        /// <summary>
        /// Primary value associated with this enumeration item
        /// </summary>
        public Int64 AEUC_val;
        /// <summary>
        /// Optional value associated with this enumeration item
        /// </summary>
        public Int64 AEUC_optval;
        /// <summary>
        /// Public empty constructor
        /// </summary>
        public GenAEUCEnumerationItem()
        {
            AEUC_displayname = "New enumeration item";
            AEUC_val = 0;
            AEUC_optval = 0;
        }
        /// <summary>
        /// Public constructor with all values set
        /// </summary>
        /// <param name="iAEUC_displayname">Display string</param>
        /// <param name="iAEUC_val">Primary value</param>
        /// <param name="iAEUC_optval">Optional value</param>
        public GenAEUCEnumerationItem(string iAEUC_displayname, Int64 iAEUC_val, Int64 iAEUC_optval)
        {
            AEUC_displayname = iAEUC_displayname;
            AEUC_val = iAEUC_val;
            AEUC_optval = iAEUC_optval;
        }
        /// <summary>
        /// Overrided ToString() method returns the display string
        /// </summary>
        /// <returns>Display string of the item</returns>
        public override string ToString()
        {
            return AEUC_displayname;
        }

        #region IAEUCSerialization Members
        /// <summary>
        /// Current element serialization state version
        /// </summary>
        public int serVersion
        {
            get
            {
                return 0x000;
            }
        }
        /// <summary>
        /// Handles object serialization
        /// </summary>
        /// <param name="srWriter">opened binary writer</param>
        public void Serialize(System.IO.BinaryWriter srWriter)
        {
            srWriter.Write(serVersion);
            Serialize_v000(srWriter);
        }
        /// <summary>
        /// Handles object deserialization
        /// </summary>
        /// <param name="srReader">opened binary reader</param>
        /// <returns>True if operation is successful</returns>
        public bool Deserialize(System.IO.BinaryReader srReader)
        {
            bool desProcState;
            int serialVer = srReader.ReadInt32();

            switch (serialVer)
            {
                case 0x000:
                    desProcState = Deserialize_v000(srReader);
                    break;
                default:
                    desProcState = false;
                    break;
            }

            return desProcState;
        }

        #region Version 0x000 serialization
        /// <summary>
        /// Version 0x000 serialization
        /// </summary>
        /// <param name="srWriter">File writer</param>
        void Serialize_v000(System.IO.BinaryWriter srWriter)
        {
            srWriter.Write(AEUC_displayname);
            srWriter.Write(AEUC_val);
            srWriter.Write(AEUC_optval);
        }
        /// <summary>
        /// Version 0x000 deserialization
        /// </summary>
        /// <param name="srReader">File reader</param>
        /// <returns>True if operation is succesful</returns>
        bool Deserialize_v000(System.IO.BinaryReader srReader)
        {
            bool NoError = true;
            try
            {
                AEUC_displayname = srReader.ReadString();
                AEUC_val = srReader.ReadInt64();
                AEUC_optval = srReader.ReadInt64();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                NoError = false;
            }
            return NoError;
        }
        #endregion
        #endregion
    }
}
